<?php
session_start();
$user = isset($_SESSION["user"])?$_SESSION["user"]:null;
if(!$user){
    echo "未登陆，请先去<a href='login.html'>登陆</a>。";
}else{
    $title = $_POST["Title"];
    $content = $_POST["Content"];
    //$createtime = (new DateTime())->format('Y-m-d H:i:s');
    date_default_timezone_set('prc');
    $createtime=date('y-m-d h:i:s',time());
    $updatetime = $createtime;
    $authorid = $user["id"];
    $authorname = $user["username"];

    $sql = "insert into `article` (`title`,`content`,`creattime`,`updatetime`,`authorname`)
    values ('$title','$content','$createtime','$updatetime','$authorname')";
    echo $sql;
    $conn = new mysqli("localhost",'root','root','mydb');
    $conn->query($sql);
    if($conn->error) echo $conn->error;
   /* $sqli = new mysqli('localhost','root','root','mydb');
    if ($sqli->connect_error) 
    die("连接失败: " . $sqli->connect_error);*/
    else echo "新文章添加成功！";
}
?>